package com.zkingsoft.actions.admin.lin;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.anotations.RemoveRequestToken;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.authority.MatrixAdapter;
import com.zkingsoft.constraint.BaseController;
import com.zkingsoft.model.lin.LinOrderLog;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.services.lin.LinOrderLogService;
import com.zkingsoft.util.WebUtil;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2017-05-08 15:14
 */
@Controller
@RequestMapping(value = "admin/linOrderLog")
public class LinOrderLogController extends BaseController {

	@Resource
	private LinOrderLogService linOrderLogService;

	@Resource
	private MatrixAdapter matrixAdapter;

	// 记录编辑前的值Before_Edit_Value
	public static final String BEV = "LinOrderLog_BEV";

	public static final String fnCode = "LinOrderLog";
	public static final String search = fnCode + ":search";
	public static final String edit = fnCode + ":edit";
	public static final String del = fnCode + ":del";
	public static final String add = fnCode + ":add";

	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(LinOrderLog linOrderLog,
			PaginationVO pageVo) {
		matrixAdapter.isBtnPermitted("LinOrder:search");
		if (pageVo == null) {
			pageVo = new PaginationVO();
		}
		pageVo.setSort("order_operattime");
		pageVo.setOrder("desc");
		return showList(linOrderLogService, linOrderLog, pageVo);
	}

	/**
	 * 新增或者修改页面
	 */
	@RemoveRequestToken
	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(LinOrderLog linOrderLog) {
		if (linOrderLog.getOrderLogId() != null) {
			matrixAdapter.isBtnPermitted(edit);
			linOrderLog.setOrderLogId(((LinOrderLog) WebUtil
					.getSessionAttribute(BEV)).getOrderLogId());
			AjaxResult result = modify(linOrderLogService,
					WebUtil.getSessionAttribute(BEV), linOrderLog,
					"linOrderLog");
			WebUtil.removeSessionAttribute(BEV);
			return result;
		} else {
			matrixAdapter.isBtnPermitted(add);
			return add(linOrderLogService, linOrderLog, "linOrderLog");
		}
	}

	/**
	 * 进入修改界面
	 */
	@SaveRequestToken
	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		matrixAdapter.isBtnPermitted(edit);
		LinOrderLog linOrderLog;
		if (id != null) {
			linOrderLog = linOrderLogService.findById(id);
			WebUtil.getRequest().setAttribute("obj", linOrderLog);
			WebUtil.setSessionAttribute(BEV, linOrderLog);
		}
		return "admin/lin/LinOrderLog-form";
	}

	/**
	 * 删除
	 */
	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		matrixAdapter.isBtnPermitted(del);
		return remove(linOrderLogService, keys);
	}

}